'use strict';

const {getDefaultModelConfig} = require("../../utils/common");

module.exports = app => {
  const { STRING, TEXT, INTEGER, DATE } = app.Sequelize;

  const Config = app.model.define('config', {
    id: {
      type: INTEGER,
      primaryKey: true,
      autoIncrement: true,
    },
    key: {
      type: STRING(100),
      allowNull: false,
      unique: true,
      comment: '配置键名',
    },
    value: {
      type: TEXT,
      allowNull: false,
      comment: '配置值',
    },
    title: {
      type: STRING(100),
      allowNull: false,
      comment: '配置标题',
    },
    description: {
      type: STRING(255),
      allowNull: true,
      comment: '配置描述',
    },
    type: {
      type: STRING(20),
      allowNull: false,
      defaultValue: 'text',
      comment: '配置类型：text-文本，image-图片，textarea-多行文本',
    },
    sort: {
      type: INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '排序',
    },
    status: {
      type: INTEGER,
      allowNull: false,
      defaultValue: 1,
      comment: '状态：0-禁用，1-启用',
    },
    ...getDefaultModelConfig(app)
  }, {
    tableName: 'config',
    timestamps: false,
    indexes: [
      {
        unique: true,
        fields: ['key']
      }
    ]
  });

  Config.associate = function() {
    // 配置模型暂时没有关联关系
  };

  return Config;
};
